import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../extension/index.dart';
import '../ui/index.dart';

class CommonTextUtils {
  ///获取一个白色字体，一般为按钮文本
  static Widget getWhite(String? text, {double fontSize = 15, FontWeight fontWeight = FontWeight.normal}) {
    return TextWidget.oneLine(text: text, color: Colors.white, fontWeight: fontWeight, fontSize: fontSize);
  }

  ///获取一个单行文本
  static Widget oneLine(
    String? text, {
    double fontSize = 15,
    FontWeight fontWeight = FontWeight.normal,
    Color fontColor = const Color(0XFF1D2129),
  }) {
    return TextWidget.oneLine(text: text, color: fontColor, fontWeight: fontWeight, fontSize: fontSize);
  }

  ///获取一个一级字体
  static Widget getText(
    String? text, {
    double fontSize = 15,
    FontWeight fontWeight = FontWeight.normal,
  }) {
    return TextWidget.oneLine(text: text, color: const Color(0XFF1D2129), fontWeight: fontWeight, fontSize: fontSize);
  }

  ///获取一个二级字体
  static Widget getText1(
    String? text, {
    double fontSize = 13,
    FontWeight fontWeight = FontWeight.normal,
  }) {
    return TextWidget.oneLine(text: text, color: const Color(0XFF4E5969), fontWeight: fontWeight, fontSize: fontSize);
  }

  ///获取一个三级字体
  static Widget getText2(
    String? text, {
    double fontSize = 12,
    FontWeight fontWeight = FontWeight.normal,
  }) {
    return TextWidget.oneLine(text: text, color: const Color(0XFF86909C), fontWeight: fontWeight, fontSize: fontSize);
  }

  ///给定一个最大宽度，根据文本内容计算高度
  static double getTextHeight(
    String? value,
    double maxWidth, {
    TextStyle? style,
  }) {
    if (value.empty) return 0;
    TextPainter painter = TextPainter(
      locale: Localizations.localeOf(Get.context!),
      textDirection: TextDirection.ltr,
      text: TextSpan(text: value, style: style),
    );
    painter.layout(maxWidth: maxWidth);

    return painter.height;
  }
}
